package com.mrogrape.notepad.activity.action.item;

import java.awt.Font;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.util.List;

import javax.swing.Action;

import com.mrogrape.notepad.activity.action.NotepadAction;
import com.mrogrape.notepad.data.ViewContext;
import com.mrogrape.notepad.resource.Settings;
import com.mrogrape.notepad.ui.FontChooser;
import com.mrogrape.notepad.ui.editor.TextEditor;


public class EditorFontSetupMenuItemAction extends NotepadAction {

	/** serialVersionUID */
	private static final long serialVersionUID = -1L;

	public EditorFontSetupMenuItemAction(){

		super.putValue(Action.NAME, "Font...");
		super.putValue(Action.SHORT_DESCRIPTION, "Setup the editor's font.");
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {

		List<TextEditor> editors = ViewContext.getMainFrame().getAllTextEditors();

		if(editors != null && !editors.isEmpty()){
			
			FontChooser fontChooser = ViewContext.getFontChooser(Settings.getSettings().getEditorFont());
			int option = fontChooser.showChooser((Frame)ViewContext.getMainFrame());
			if(option == FontChooser.APPROVE_OPTION){
				
				Font font = fontChooser.getSelectedFont();
				Settings.getSettings().setEditorFont(font);
				for(TextEditor editor : editors){
					editor.setEditorFont(font);
				}
			}
		}
	}
}
